﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    /// <summary>
    /// 每个学生的实体类
    /// </summary>
    public class Student
    {
        public string Name { get; set; }
        public Int32[] grades = new Int32[5] { 0, 0, 0, 0, 0 };
    }

    public class Program
    {

        /*15个学生考试5次，把学生名字存入一维数组，成绩存入二维数组，并输出所有学生名字、考试成绩、平均成绩*/
        static void Main(string[] args)
        {
            //学生链表
            List<Student> stuList = new List<Student>();
            Random random = new Random();
            //给各个学生姓名、成绩赋值
            for (int i = 1; i <= 3; i++)
            {
                Student student = new Student();
                Console.Write("请输入学生姓名:     ");
                //从控制台读取姓名
                student.Name = Console.ReadLine();
                //从控制台读取成绩
                Console.Write("请输入5门课程成绩，以空格分割： ");
                string strGrade = Console.ReadLine();
                string[] strGrades = strGrade.Trim().Split(new char[] { ' ' });
                for (int j = 0; j < strGrades.Length; j++)
                {
                    //给学生的成绩赋值
                    student.grades[j] = Int32.Parse(strGrades[j]);
                }
                //将 每个学生实体  添加到链表
                stuList.Add(student);
            }

            //遍历输出学生的姓名、成绩、平均成绩
            Console.WriteLine();
            foreach (Student stu in stuList)
            {
                Console.WriteLine("姓名：{0}", stu.Name);
                Console.Write("成绩：");
                foreach (Int32 grade in stu.grades)
                {
                    Console.Write(grade.ToString() + "    ");
                }
                Console.WriteLine();
                Console.Write("平均成绩：{0}", stu.grades.Average().ToString());
                Console.WriteLine();
                Console.WriteLine();
            }
          
            Console.ReadKey();
        }
    }


}
